let express = require('express');
let app = express();
let whiteList=['http://localhost:2222'];
app.use(function (req,res,next) {
    let  origin=req.headers.origin;
    if(whiteList.includes(origin)){
        //允许源访问我
        res.setHeader('Access-Control-Allow-Origin',origin);
        //允许访问我
        res.setHeader('Access-Control-Allow-Headers','name');
        res.setHeader('Access-Control-Allow-Methods','PUT');
        //预检的存活时间‰
        res.setHeader('Access-Control-Allow-Max-Age',6000);
        //允许携带cookie
        res.setHeader('Access-Control-Allow-Credentials',true);
        //允许返回的头
        res.setHeader('Access-Control-Expose-Headers','name');
        if(req.method==='OPTIONS'){
            res.end();
        }
    }
    next();
});
app.put('/getData',function (req,res) {
    console.log(req.headers);
    res.setHeader('name','jw12321');
    res.end("我不爱你")
})

app.listen(1234);
console.log('监听1234端口。。');
